/**
  * 系统管理--用户管理的单例对象
 */
var SubjectsResult = {
    id: "SubjectsResultTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    deptid:0
};

/**
 * 初始化表格的列
 */
SubjectsResult.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '学生姓名', field: 'studentName', visible: true, align: 'center', valign: 'middle'},
            {title: '题目类型名称', field: 'className', visible: true, align: 'center', valign: 'middle'},
            {title: '答对题目数', field: 'tmRight', visible: true, align: 'center', valign: 'middle'},
            {title: '题目类别', field: 'examClass', visible: true, align: 'center', valign: 'middle'},
            {title: '选项', field: 'voiceHelp', visible: true, align: 'center', width:'250px', valign: 'middle'}
        ];
    return columns;
};

/**
 * 检查是否选中
 */
SubjectsResult.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    alert(selected.id);
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        SubjectsResult.seItem = selected;
        return true;
    }
};

SubjectsResult.singleCheck = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
    	if (selected.length >1) {
            Feng.info("请先选中表格中的某一记录！");
            return false;
        }else{
        	 SubjectsResult.seItem = selected[0];
             return true;
        } 
    }
};

/**
 * 点击添加
 */
SubjectsResult.openAddSubjectsResult = function () {
    var index = layer.open({
        type: 2,
        title: '添加试题',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/SubjectsResult/SubjectsResult_add'
    });
    this.layerIndex = index;
};

/**
 * 点击修改按钮时
 * @param userId 
 */
SubjectsResult.openChange = function () {
    if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '编辑课程',
            area: ['90%', '90%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/SubjectsResult/toUpdate/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};
SubjectsResult.openView = function(){
	if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '课程详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/SubjectsResult/view/' + this.seItem.id
        });
        this.layerIndex = index;
    }
}

SubjectsResult.openDel = function () {
    if (this.singleCheck()) {
    	
    	var id=this.seItem.id;
        var operation = function(){
            var userId = SubjectsResult.seItem.id;
            var ajax = new $ax(Feng.ctxPath + "/SubjectsResult/delete", function (data) {
            	if(data.resultCode==0){
            		Feng.success("删除成功!");
            		SubjectsResult.table.refresh();
            	}else{
            		Feng.error(data.msg + "!");
            	}              
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", id);
            ajax.start();
        };

        Feng.confirm("是否删除选中的题目?",operation);
    }
};




SubjectsResult.resetSearch = function () {
    $("#questClassId").val("");
    $("#courseId").val("");
    $("#classId").val("");
    SubjectsResult.table.refreshOptions({pageNumber:1});
    SubjectsResult.search();
}

SubjectsResult.search = function () {
    var queryData = {};
    queryData['questClassId'] = $("#questClassId").val();
    queryData['courseId'] = $("#courseId").val();
    queryData['classId'] = $("#classId").val();
    SubjectsResult.table.refreshOptions({pageNumber:1});
    SubjectsResult.table.refresh({query: queryData});
}

$(function () {
	var paramsId =[
	      {
	    	  "key":"questClassId",
	    	  "type":"select",
	    	  "id":"questClassId"
	       },
	       {
		    	  "key":"courseId",
		    	  "type":"input",
		    	  "id":"courseId"
		   },
	       {
		       "key":"classId",
		       "type":"select",
		       "id":"classId"
		   }
	];
    var defaultColunms = SubjectsResult.initColumn();
    var table = new BSTable("SubjectsResultTable", "/subjects/result/list", defaultColunms,paramsId);
    table.setPaginationType("server");
    SubjectsResult.table = table.init();
    
    $("#questClassId").change(function(){
    	var questClassId= $("#questClassId").val();
    	var ajax = new $ax(Feng.ctxPath + "/subject/result/findById", function (data) {
        	if(data.resultCode==0){
        		 $("#questClassId").html("");
        		 $("#workName").val("");
        		 var html="";
        		 var sclass=data.data.classList;
        		 $.each(sclass,
                    function(idx, item) {
                        html += '<option value="' + item.id + '">' + item.className + '</option>';
                    });
                $("#questClassId").append(html);
                var courseName=data.data.sc.courseName;
                $("#courseName").val(courseName);
                html="";
        		SchoolStudentWork.table.refresh();
        	}else{
        		Feng.error(data.msg + "!");
        	}              
        }, function (data) {
            Feng.error("!" + data.responseJSON.message + "!");
        });
        ajax.set("questClassId", questClassId);
        ajax.start();
    });
});






